﻿@model Tau.ViewModels.AddImage

@using (Html.BeginForm("AddNewImage", "ImageAdmin", FormMethod.Post,
                            new { id = "addNewImageForm", enctype = "multipart/form-data", target = "imageFrame" }))
{
    @Html.ValidationSummary(true)
    
        <table>
            <tr>
                <td colspan="2">
                   Add new image: <input type="file" id="imageToUpload" name="imageToUpload" size="35" /> 
                </td>
            </tr>
             <tr>
                <td>
                    Image category: @Html.DropDownListFor(model => model.AddingImage.Category, new SelectList(new List<string> { "Book", "CD", "DVD", "Other" }))
                </td>
                <td align="right">
                    @Html.HiddenFor(model => model.Mode)
                </td>
            </tr>
            <tr>
                <td align="right">
                     <a href="#" onclick="uploadImage();">save image</a>
                </td>
            </tr>
        </table>
}

<script language="javascript" type="text/javascript">
    function uploadImage() {

        showProgress();
        
        var fileInput;

        fileInput = $("#imageToUpload");

        var fileName = fileInput.val();

        if (fileName.indexOf(".jpg") == -1 &&
            fileName.indexOf(".bmp") == -1 &&
            fileName.indexOf(".gif") == -1 &&
            fileName.indexOf(".tif") == -1 &&
            fileName.indexOf(".tiff") == -1 &&
            fileName.indexOf(".png") == -1)
        {
            hideProgress();
            fileInput.val("");
            alert("Selected file is not an allowable file format.  Please select an image file");
            return;
        }

        $("#addNewImageForm").submit();

        hideProgress();
    }
</script>
 

